<!DOCTYPE>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>主页</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="/lib/font-awesome-4.7.0/css/font-awesome.min.css" >
    <link rel="stylesheet" href="/css/public.css" >
</head>
<style>
    .layui-card-body{height: 500px;float:top}
    .layui-card {border:1px solid #f2f2f2;border-radius:5px;}
    .icon {margin-right:10px;color:#1aa094;}
    .icon-cray {color:#ffb800!important;}
    .icon-blue {color:#1e9fff!important;}
    .icon-tip {color:#ff5722!important;}
    .layuimini-qiuck-module {text-align:center;margin-top: 10px}
    .layuimini-qiuck-module a i {display:inline-block;width:100%;height:60px;line-height:60px;text-align:center;border-radius:2px;font-size:30px;background-color:#F8F8F8;color:#333;transition:all .3s;-webkit-transition:all .3s;}
    .layuimini-qiuck-module a cite {position:relative;top:2px;display:block;color:#666;text-overflow:ellipsis;overflow:hidden;white-space:nowrap;font-size:14px;}
    .welcome-module {width:100%;height:210px;}
    .panel {background-color:#fff;border:1px solid transparent;border-radius:3px;-webkit-box-shadow:0 1px 1px rgba(0,0,0,.05);box-shadow:0 1px 1px rgba(0,0,0,.05)}
    .panel-body {padding:10px}
    .panel-title {margin-top:0;margin-bottom:0;font-size:12px;color:inherit}
    .label {display:inline;padding:.2em .6em .3em;font-size:75%;font-weight:700;line-height:1;color:#fff;text-align:center;white-space:nowrap;vertical-align:baseline;border-radius:.25em;margin-top: .3em;}
    .layui-red {color:red}
    .main_btn > p {height:40px;}
    .layui-bg-number {background-color:#F8F8F8;}
    .layuimini-notice:hover {background:#f6f6f6;}
    .layuimini-notice {padding:7px 16px;clear:both;font-size:12px !important;cursor:pointer;position:relative;transition:background 0.2s ease-in-out;}
    .layuimini-notice-title,.layuimini-notice-label {
        padding-right: 70px !important;text-overflow:ellipsis!important;overflow:hidden!important;white-space:nowrap!important;}
    .layuimini-notice-title {line-height:28px;font-size:14px;}
    .layuimini-notice-extra {position:absolute;top:50%;margin-top:-8px;right:16px;display:inline-block;height:16px;color:#999;}
    .layui-top-box {padding:0px 0px 0px 0px;color:#fff}/*改*/
    .panel {margin-bottom:17px;background-color:#fff;border:1px solid transparent;border-radius:3px;-webkit-box-shadow:0 1px 1px rgba(0,0,0,.05);box-shadow:0 1px 1px rgba(0,0,0,.05)}
    .panel-body {padding:15px}
    .panel-title {margin-top:0;margin-bottom:0;font-size:14px;color:inherit}
    .label {display:inline;padding:.2em .6em .3em;font-size:75%;font-weight:700;line-height:1;color:#fff;text-align:center;white-space:nowrap;vertical-align:baseline;border-radius:.25em;margin-top: .3em;}
    .layui-red {color:red}
    .main_btn > p {height:40px;}
</style>
<body>
<div class="layuimini-container">
    <div class="layuimini-main layui-top-box">
        <div class="layui-row layui-col-space10">

            <div class="layui-col-md3">
                <div class="col-xs-6 col-md-3">
                    <div class="panel layui-bg-cyan">
                        <div class="panel-body">
                            <div class="panel-title">
                                <span class="label pull-right layui-bg-blue">实时</span>
                                    <h5>用户统计</h5>
                            </div>
                            <div class="panel-content">
                                <h5 class="no-margins" ><spqn id="div1"></spqn></h5>
                                <small>当前分类总记录数</small>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-col-md3">
                <div class="col-xs-6 col-md-3">
                    <div class="panel layui-bg-blue">
                        <div class="panel-body">
                            <div class="panel-title">
                                <span class="label pull-right layui-bg-cyan">实时</span>
                                <h5>商品统计</h5>
                            </div>
                            <div class="panel-content">
                                <h5 class="no-margins" id="div2"></h5>
                                <small>当前分类总记录数</small>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-col-md3">
                <div class="col-xs-6 col-md-3">
                    <div class="panel layui-bg-green">
                        <div class="panel-body">
                            <div class="panel-title">
                                <span class="label pull-right layui-bg-orange">实时</span>
                                <h5>浏览统计</h5>
                            </div>
                            <div class="panel-content">
                                <h5 class="no-margins" id="div3"></h5>
                                <small>当前分类总记录数</small>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-col-md3">
                <div class="col-xs-6 col-md-3">
                    <div class="panel layui-bg-orange">
                        <div class="panel-body">
                            <div class="panel-title">
                                <span class="label pull-right layui-bg-green">实时</span>
                                <h5>订单统计</h5>
                            </div>
                            <div class="panel-content">
                                <h5 class="no-margins" id="div4"></h5>
                                <small>当前分类总记录数</small>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
    <div >
        <div class="layui-card layui-col-md6">
            <div class="layui-card-header"><i class="fa fa-line-chart icon"></i>报表统计</div>
            <div class="layui-card-body layui-col-md12">
                <div id="echarts-records" style="min-height:400px;padding: 10px"></div>
            </div>
        </div>
        <!--柱状图-->
        <div class="layui-col-xs12 layui-col-md6 layui-card">
            <div id="echarts-dataset" style="background-color:#ffffff;min-height:300px;padding: 10px"></div>
        </div>
        <div style="height: 300px" class="layui-col-xs12 layui-col-md6 layui-card">
            <table class="layui-table"  id="addUserList" lay-skin="line">
                <colgroup>
                    <col width="150">
                    <col width="200">
                </colgroup>
                <thead>
                    <th style="text-align: center;color: red" colspan="2">销量最好的商品</th>
                </thead>
                <tbody>
                <tr>
                    <td  style="text-align: center;width: 30%" >产品名称</td>
                    <td ></td>
                </tr>
                <tr>
                    <td style="text-align: center">产品类型</td>
                    <td>于千万人之中遇见你所遇见的人，于千万年之中，时间的无涯的荒野里…</td>
                </tr>
                <tr>
                    <td style="text-align: center">产品价格</td>
                    <td>于千万人之中遇见你所遇见的人，于千万年之中，时间的无涯的荒野里…</td>
                </tr>
                <tr>
                    <td style="text-align: center">产品库存</td>
                    <td>于千万人之中遇见你所遇见的人，于千万年之中，时间的无涯的荒野里…</td>
                </tr>
                <tr>
                    <td style="text-align: center">购买量</td>
                    <td>于千万人之中遇见你所遇见的人，于千万年之中，时间的无涯的荒野里…</td>
                </tr>
                <tr>
                    <td style="text-align: center">上架时间</td>
                    <td>于千万人之中遇见你所遇见的人，于千万年之中，时间的无涯的荒野里…</td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>
<script src="/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="/lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script>

    var hotsale;

    $.ajax({
        url: "/admin/index1",
        type: "GET",
        dataType : "json",
        success: function (data) {
            $("#addUserList tbody").remove();
            JSON.stringify(data)
            document.getElementById('div1').innerText  = data.usercount;//给HTML元素的value属性赋值
            document.getElementById('div2').innerText = data.goodscount;//给HTML元素的value属性赋值
            document.getElementById('div3').innerText = data.viewscount;//给HTML元素的value属性赋值
            document.getElementById('div4').innerText = data.ordercount;//给HTML元素的value属性赋值
            console.log(data.hotsale);
            $("#addUserList").append('<tbody><tr><td  style="text-align: center;width: 30%" >产品名称</td><td >'+
                data.hotsale.gname+'</td></tr><tr><td style="text-align: center">产品类型</td><td>'+
                data.hotsale.item+'</td></tr><tr><td style="text-align: center">产品价格</td><td>'+
                data.hotsale.price+'</td></tr><tr><td style="text-align: center">产品库存</td><td>'+
                data.hotsale.goodsNumber+'</td></tr><td style="text-align: center">购买量</td><td>'+
                data.hotsale.sales+'</td></tr><tr><td style="text-align: center">上架时间</td><td>'+
                data.hotsale.creationTime+'</td></tr></tbody>');
        }
    })

    layui.use(['layer', 'miniTab','echarts'], function () {
        var $ = layui.jquery,
            layer = layui.layer,
            miniTab = layui.miniTab,
            echarts = layui.echarts;

        var nums =[];
        $.ajax({
            type:"GET",
            url:"/orders/index",
            dataType:"json",
            async:false,
            success:function (result) {
                nums.push(result['date']);
                nums.push(result['size']);
/*                console.log(result)
                console.log(result['date'])
                console.log(nums[0])
                console.log(nums[1])*/
            },
            error :function(errorMsg) {
                alert("获取后台数据失败！");
            }
        });

        miniTab.listen();


        /**
         * 报表功能
         */
        var echartsRecords = echarts.init(document.getElementById('echarts-records'), 'walden');
        var optionRecords = {
            tooltip: {
                trigger: 'axis'
            },
            legend: {
                data:['订单详情']
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            toolbox: {
                feature: {
                    saveAsImage: {}
                }
            },
            xAxis: {
                type: 'category',
                boundaryGap: false,
                data: nums[0]  /*时间 横坐标*/
            },
            yAxis: {
                type: 'value'
            },
            series: [
                {
                    name:'订单详情',
                    type:'line',
                    data: nums[1]
                }
            ]
        };
        echartsRecords.setOption(optionRecords);



        /**
         * 柱状图
         */
        var data=[];
        var date1=[];
        var date2=[];
        var date3=[];
        $.ajax({
            type:"GET",
            url:"/goods/index1",
            dataType:"json",
            async:false,
            success:function (result) {
                data.push(result['date'])
                data.push(result['size2'])
                data.push(result['size3'])
                date1=data[0]
                date2=data[1]
                date3=data[2]
            },
            error :function(errorMsg) {
                alert("获取后台数据失败！");
            }
        });

        var echartsDataset = echarts.init(document.getElementById('echarts-dataset'), 'walden');
        var optionDataset = {
            legend: {},
            tooltip: {},
            dataset: {
                dimensions: ['product', '用户统计', '商品统计', '浏览统计'],
                source: [
                    {product: date1[0], '用户统计': 43.3, '商品统计': date3[0], '浏览统计': date2[0]},
                    {product: date1[1], '用户统计': 83.1, '商品统计': date3[1], '浏览统计': date2[1]},
                    {product: date1[2], '用户统计': 86.4, '商品统计': date3[2], '浏览统计': date2[2]},
                    {product: date1[3], '用户统计': 72.4, '商品统计': date3[3], '浏览统计': date2[3]}
                ]
            },
            xAxis: {type: 'category'},
            yAxis: {},
            // Declare several bar series, each will be mapped
            // to a column of dataset.source by default.
            series: [
                {type: 'bar'},
                {type: 'bar'},
                {type: 'bar'}
            ]
        };

        echartsDataset.setOption(optionDataset);


        window.onresize = function () {
            echartsDataset.resize();
            echartsRecords.resize();
        }


        function chartssize (container,charts) {
            function getStyle(el, name) {
                if (window.getComputedStyle) {
                    return window.getComputedStyle(el, null);
                } else {
                    return el.currentStyle;
                }
            }
            var wi = getStyle(container, 'width').width;
            var hi = getStyle(container, 'height').height;
            charts.style.width = wi
            charts.style.height = hi
        }


    });
</script>
<!--<script th:inline="javascript">
    var message = [[${usercount}]];
    console.log(message);
</script>-->
</body>
</html>